﻿/* ************************************************************
 * Namespace: JumpFleetGameLib.xMap.SectorMap
 * Class:  StaticBackgroundTile
 * Author:  Roy Penrod
 * 
 * A static background tile is a background tile without 
 * animations.  It contains an xSprite.StaticSprite object.
 *  
 * ************************************************************ */

using System;
using Microsoft.Xna.Framework;

namespace JumpFleetGameLib.xMap.SectorMap
{
    public class StaticBackgroundTile : BackgroundTile
    {
        #region MEMBERS

        // holds the static sprite
        private xSprite.StaticSprite _sprite;          

        // holds a reference to the xSprite.SpriteManager object
        private xSprite.SpriteManager _spriteManager;

        // name of the static sprite template this tile was based off of
        private string _spriteTemplateName;

        #endregion


        #region PROPERTIES

        /// <summary>
        /// Position of the background tile on the screen.  Type: Vector2
        /// </summary>
        public override Vector2 Position
        {
            get
            {
                return base.Position;
            }
            set
            {
                // set the tile's position
                base.Position = value;
                
                // set the sprite's DrawPosition equal to the tile's position
                _sprite.DrawPosition = base.Position;

            }
        }

        /// <summary>
        /// Layer depth of the background tile.  Type: float
        /// </summary>
        public override float Layer
        {
            get
            {
                return base.Layer;
            }
            set
            {
                // sets the tile's layer
                base.Layer = value;

                // sets the sprite's Layer equal to the tile's layer
                _sprite.Layer = base.Layer;
            }
        }

        /// <summary>
        /// Flag for whether the background tile is visible.  Type: bool
        /// </summary>
        public override bool Visible
        {
            get
            {
                return base.Visible;
            }
            set
            {
                // sets the tile's visible flag
                base.Visible = value;

                // sets the sprite's visible flag equal to the tile's visible flag
                _sprite.Visible = base.Visible;
            }
        }

        #endregion


        #region CONSTRUCTORS       
        
        /// <summary>
        /// Constructor for the StaticBackgroundTile class.  The Visible property defaults to false.  The Position property defaults to 0,0.
        /// </summary>
        /// <param name="spriteManager">Reference to the xSprite.SpriteManager object.  Type: xSprite.SpriteManager</param>
        /// <param name="spriteTemplateName">The name you used when you created the static sprite template.  Type: string</param>
        /// <param name="tileTag">Tag to identify the kind of background tile.  Type: string</param>
        /// <param name="tileWidth">Width of the background tile.  Type: int</param>
        /// <param name="tileHeight">Height of the background tile. Type: int</param>
        /// <param name="tileLayer">Layer depth of the background tile.  Type: float</param>    
        public StaticBackgroundTile(xSprite.SpriteManager spriteManager, string spriteTemplateName, string tileTag, int tileWidth, int tileHeight, float tileLayer) :
            base (tileTag, tileWidth, tileHeight, tileLayer)
        {
            // stores a reference to the SpriteManager object
            _spriteManager = spriteManager;

            // assigns the sprite template name 
            _spriteTemplateName = spriteTemplateName;

            // creates the static sprite from the template
            _sprite = spriteManager.CreateNewStaticSpriteFromTemplate(spriteTemplateName);

            // sets the sprite's DrawPosition to the default of 0, 0
            _sprite.DrawPosition = new Vector2(0, 0);

            // sets the sprite's Layer to the tile's layer
            _sprite.Layer = tileLayer;

            // defaults the tile's Visible flag to false
            Visible = false;

            // sets the sprite's Visible flag to the default
            _sprite.Visible = Visible;
        }

        #endregion


        #region METHODS

        // creates a copy of the StaticBackgroundTile object
        public StaticBackgroundTile Clone()
        {
            // creates a new StaticBackgroundTile object with the same properties
            StaticBackgroundTile newStaticBackgroundTile = new StaticBackgroundTile(this._spriteManager, this._spriteTemplateName, this.Tag, this.Width, this.Height, this.Layer);

            // copies the StaticBackgroundTile Position property
            // set it to make sure it copies the property info 
            // to the xSprite.StaticSprite object
            newStaticBackgroundTile.Position = this.Position;

            // copies the StaticBackgroundTile's Layer property
            // set it to make sure it copies the property info 
            // to the xSprite.StaticSprite object
            newStaticBackgroundTile.Layer = this.Layer;

            // copies the StaticBackgroundTile's Visible property
            // set it to make sure it copies the property info 
            // to the xSprite.StaticSprite object
            newStaticBackgroundTile.Visible = this.Visible;

            // returns the new StaticBackgroundTile object
            return newStaticBackgroundTile;
        }
        
        #endregion
    } // <-- end class
} // <-- end namespace
